package org.dubnation.org.controller;

import org.dubnation.org.service.IShopOperateLogService;
import org.dubnation.org.domain.ShopOperateLog;
import org.dubnation.org.query.ShopOperateLogQuery;
import org.dubnation.base.util.AjaxResult;
import org.dubnation.base.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shopOperateLog")
public class ShopOperateLogController {
    @Autowired
    public IShopOperateLogService shopOperateLogService;


    /**
     * 保存和修改公用的
     * @param shopOperateLog  传递的实体
     * @return Ajaxresult转换结果
     */
    @PutMapping
    public AjaxResult insertOrUpdate(@RequestBody ShopOperateLog shopOperateLog){
        if( shopOperateLog.getId()!=null)
            shopOperateLogService.update(shopOperateLog);
        else
            shopOperateLogService.insert(shopOperateLog);
        return AjaxResult.me();
    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        shopOperateLogService.delete(id);
        return AjaxResult.me();
    }
	
    //获取用户
    @GetMapping("/{id}")
    public AjaxResult queryById(@PathVariable("id")Long id)
    {
        ShopOperateLog shopOperateLog = shopOperateLogService.queryById(id);
        return AjaxResult.me().setData(shopOperateLog);
    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping
    public AjaxResult queryAll(){
        List< ShopOperateLog> list = shopOperateLogService.queryAll();
        return AjaxResult.me().setData(list);
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping
    public AjaxResult queryPage(@RequestBody ShopOperateLogQuery query) {
        PageInfo<ShopOperateLog> pageInfo = shopOperateLogService.queryPage(query);
        return AjaxResult.me().setData(pageInfo);
    }

    /**
    * 批量删除数据
    * @param ids
    * @return
*/
    @PatchMapping
    public AjaxResult batchDelete(@RequestBody List<Long> ids) {
        shopOperateLogService.batchDelete(ids);
        return AjaxResult.me();
    }

    /**
     * 查询驳回日志
     * @param shopId
     * @return
     */
    @GetMapping("/rejectLogs/{shopId}")
    public AjaxResult getRejectLogs(@PathVariable("shopId") Long shopId){
        List<ShopOperateLog> rejectLogList = shopOperateLogService.getRejectLogs(shopId);
        return AjaxResult.me().setData(rejectLogList);
    }

}
